﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ClientRegister
{
    public partial class ListSubjectsForm : Form
    {
        public ListSubjectsForm()
        {
            InitializeComponent();
        }

        SubjectsDataProvider sub = new SubjectsDataProvider();
        SynchronizeData sync = new SynchronizeData();

        private void ListSubjectsForm_Load(object sender, EventArgs e)
        {
            GridListSub.DataSource = sub.LoadSubject().Tables[0];
        }

        private void btnRemove_Click(object sender, EventArgs e)
        {
            if (GridListSub.SelectedCells.Count > 0)
            {
                string ID = GridListSub.CurrentRow.Cells["ID"].Value.ToString();
                string xml = sub.SelectAndConvertXMLSub(ID);
                if (sub.DeleteSub(ID) != 0)
                {
                    sync.transfDataForDeleteMethod(xml, sync.SubTb);
                    MessageBox.Show("Đã xóa");
                }
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            GridListSub.DataSource = sub.LoadSubject().Tables[0];
        }
    }
}
